package com.cyf.db.mapper;

import com.cyf.db.bean.CarWashDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

/**
 * 洗车券使用情况，云端表
 * @author hfy
 * @date 2018/7/11
 */
public interface CarWashDetailMapper {

    @Select("SELECT COUNT(id) FROM carwash_detail " +
            "where couponId = #{couponId} and parkingId = #{parkingId}")
    Integer countByCouponIdAndParkingId(@Param("couponId") int couponId, @Param("parkingId") Integer parkingId);

    @Insert("insert into carwash_detail(parkingId, send, couponId, beforeUseCount, afterUseCount, useTime) " +
            "values(#{detail.parkingId}, 0, #{detail.couponId}, " +
            "#{detail.beforeUseCount}, #{detail.afterUseCount}, #{detail.useTime})")
    @SelectKey(statement="select LAST_INSERT_ID()", keyProperty="detail.id", before=false, resultType=int.class, keyColumn = "id")
    void insert(@Param("detail") CarWashDetail carWashDetail);
}
